package com.sskj.mine.invite;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.lzy.okrx2.adapter.FlowableBody;
import com.sskj.common.base.HttpData;
import com.sskj.lib.http.JsonCallBack;
import com.sskj.lib.http.JsonConverter;
import com.sskj.mine.bean.InvireTeamRecord;
import com.sskj.mine.bean.InviteRecord;
import com.sskj.mine.http.HttpConfig;
import com.sskj.mine.presenter.BasePresenter;
import com.sskj.mine.invite.TeamActivity;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.Flowable;


/**
 * @author Hey
 * Create at  2019/05/03
 */
class TeamPresenter extends BasePresenter<TeamActivity> {
    public void getRecord() {
        OkGo.<HttpData<InvireTeamRecord>>get(HttpConfig.BASE_URL + HttpConfig.INVITEREAMRECORD)
                .execute(new JsonCallBack<HttpData<InvireTeamRecord>>(this) {
                    @Override
                    public void onSuccess(Response<HttpData<InvireTeamRecord>> response) {
                        HttpData<InvireTeamRecord> body = response.body();
                        if (body.getStatus() == HttpConfig.OK) {
                            mView.updateUi(body.getData());
                        }
                    }
                });
    }

    public Flowable<List<InvireTeamRecord.InviteList>> getRecordList(String page, String size) {
        return OkGo.<HttpData<InvireTeamRecord>>get(HttpConfig.BASE_URL + HttpConfig.INVITEREAMRECORD)
                .params("p", page)
                .params("size", size)
                .converter(new JsonConverter<HttpData<InvireTeamRecord>>() {
                })
                .adapt(new FlowableBody<>())
                .map(invireTeamRecordHttpData -> invireTeamRecordHttpData.getData().getList())
                .onErrorReturnItem(new ArrayList<>());

    }

}
